package cn.wolfcode.wms.controllrer;

import cn.wolfcode.wms.page.PageResult;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IPermissionService;
import cn.wolfcode.wms.vo.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService ;

    @RequestMapping("/list")
    public String list(Model model ,QueryObject qo){


        PageResult pageResult = permissionService.query(qo);

        model.addAttribute("pageResult",pageResult);
        return "permission/list";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JSONResult delete(Long id){
        try {
            permissionService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }

        return  JSONResult.success("删除成功");
    }


    @RequestMapping("/load")
    @ResponseBody
    public JSONResult load(Long id){
        try {
            permissionService.load(id);
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }

        return  JSONResult.success("删除成功");
    }






}
